package model;

import java.util.ArrayList;

import common.DataManager;
import common.GridCoordinate;
import controller.Controller;

/**
 * @author Colin
 * 
 * The BrickWall class is a type of defensive item that
 * will stop zombosaurs until its health has been depleted
 */

public class BrickWall extends DefensiveItem{
	
	private static final int INITIAL_HEALTH = 5;
	private static final int INITIAL_DAMAGE = 0;
	private static final int COST = 400;
	
	private boolean destroyed = false;
	private float remainingHealth = INITIAL_HEALTH;
	
	private ArrayList<Zombosaur> stoppedZombosaurs = new ArrayList<Zombosaur>();
	
	//BrickWall without position
	public BrickWall(){
		super("Brick Wall", DataManager.BRICK_WALL, COST, INITIAL_HEALTH, INITIAL_DAMAGE);
		remainingHealth = INITIAL_HEALTH;
	}
	
	//BrickWall with position
	public BrickWall(GridCoordinate position) {
		super("Brick Wall", DataManager.BRICK_WALL, COST, position, INITIAL_HEALTH, INITIAL_DAMAGE);
		remainingHealth = INITIAL_HEALTH;
	}

	/**
	 * Health is decreased by the amount of damage.
	 */
	public void onContact( Zombosaur zombosaur){
		if(zombosaur instanceof Pzombiedactyl) return;
		remainingHealth = remainingHealth - zombosaur.getDamage()/(float)Controller.ticksPerSecond;
		zombosaur.stop();
		stoppedZombosaurs.add(zombosaur);
		if(remainingHealth <= 0.0f){
			destroyed(zombosaur);
		}
	}
	
	private void destroyed(Zombosaur zombosaur){
		for(int i = 0; i < stoppedZombosaurs.size(); i++) stoppedZombosaurs.get(i).resumeSpeed();
		stoppedZombosaurs.clear();
		this.destroyed = true;
	}
	
	public boolean isDestroyed(){
		return destroyed;
	}

	@Override
	public String getDescription() {
		return "The brick wall can hold most zombosaurs at bay for a moderate amount of time";
	}

}
